﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace File_Renamer
{
    class FileName
    {
        /// <summary>
        /// 
        /// </summary>
        public string NewFullName
        {
            get
            {
                return string.Format("{0}\\{1}.{2}", this.Location, this.NewName, this.Extension);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public string FullName
        {
            get
            {
                return string.Format("{0}\\{1}.{2}", this.Location, this.Name, this.Extension);
            }
            set
            {
                try
                {
                    // split apart folders and file name (e.g. "\\tserv01\folder\file.doc" becomes {"tserv01", "folder", "file.doc"})
                    this.PathPieces = value.Split('\\');

                    // rebuild location portion of full name and store it
                    this.Location = string.Empty;
                    for (int i = 1; i < (this.PathPieces.Length - 1); i++) // starting this at 1 is a fix for too many backslashes with UNC path names
                    {
                        this.Location += '\\' + this.PathPieces[i];
                    }

                    // split apart filename and extension (e.g. "file.doc" becomes {"file", "doc"})
                    string[] fileNameAndExtPieces = this.PathPieces[this.PathPieces.Length - 1].Split('.');
                    this.Name = fileNameAndExtPieces[0];
                    this.Extension = fileNameAndExtPieces[1];
                }
                catch (Exception e)
                {
                    //resultsBox.Text += e.ToString() + Environment.NewLine;
                    this.IsValid = false;
                }

                this.IsValid = true;
            }
        }

        public string[] PathPieces { get; set; }

        public string Extension { get; set; }

        public string Name { get; set; }

        public string NewName { get; set; }

        public string Location { get; set; }

        public bool IsValid { get; set; }
    }
}
